package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/activities")
@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result list(ActivityDto activityDto) {
        PageResult<Activity> list = activityService.list(activityDto);
        return Result.success(list);
    }


    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.deleteById(id);
        return Result.success();
    }


    @PostMapping
    public Result add(@RequestBody Activity activity) {
        activityService.add(activity);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result get(@PathVariable Integer id) {
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result update(@RequestBody Activity activity) {
        activityService.upDate(activity);
        return Result.success();
    }


    @GetMapping("/type/{type}")
     public Result listByType(@PathVariable String type) {
        List<Activity> list = activityService.listByType(type);
        return Result.success(list);
    }
}
